<?php

/* SPLIT PROXY FROM URL TO QUERY. QUERY: ALL INSIDE THE 'S' PARAMETER */
        $s = str_replace(" ", "%20", $_GET['url']);
        $url = str_replace("wwwdev", "www", $_GET['url']);
        //echo $url;
        //$url = $s;


/* SET INTERNAL PROXY */
        //$proxy = "";
        //$proxy = "http://wwwcache.ebi.ac.uk:3128/";
        $proxy = "http://wwwcache.sanger.ac.uk:3128/";


/* CURL CONFIGURARTION */
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        //curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 50);
        //curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 4);
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
        curl_setopt($ch, CURLOPT_TIMEOUT, 10);
        //curl_setopt($ch, CURLOPT_TIMEOUT, 50);
        //curl_setopt($ch, CURLOPT_TIMEOUT, 8);
        curl_setopt($ch, CURLOPT_HEADER, 1);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        if(strlen($proxy) != 0){
                //curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 1);
                curl_setopt($ch, CURLOPT_PROXY, "$proxy");
        }
        /* Don't return HTTP headers. Do return the contents of the call */
        curl_setopt($ch, CURLOPT_HEADER, 0);


/* DISPLAY DATA FROM THE ORIGINAL QUERY */
        $data = curl_exec($ch);
        curl_close($ch);
        $flag = strpos($url, "pdbe");
        if($flag){
            header("Content-Type: text/plain");
        }else{
            header("Content-Type: text/xml");
        }
        echo $data;
?>